package com.zlc.sykks.interceptor;

import com.zlc.sykks.entity.UserDTO;
import com.zlc.sykks.utils.UserHodler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/*
*  登录拦截器
* */
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //1.判断是否需要拦截
        UserDTO userDTO = UserHodler.getUser();
        //2.拦截
        if(userDTO == null){
            //没有，需要拦截，设置状态码     //401表示没有权限!!!
            response.setStatus(401);
            //拦截
            return false;
        }
        //3.放行
        return true;
    }
}
